#include <bits/stdc++.h>
using namespace std;
inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') {
            f = -1;
        }
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0', ch = getchar();
    }
    return x * f;
}
const int MAXN = 100005;
int n, m, l, v1, t;
int d[MAXN], v[MAXN], a[MAXN], p[MAXN], p2[MAXN];
vector<int> p1[MAXN];
int main() {
	//freopen("detect.in", "r", stdin);
	//freopen("detect.out", "w", stdout);
	t = read();
	while (t--) {
        int cnt = 0;
        n = read();
        m = read();
        l = read();
        v1 = read();
        for (int i = 0; i < n; i++) {
            d[i] = read();
            v[i] = read();
            a[i] = read();
        }
        for (int i = 0; i < m; i++) {
            p[i] = read();
        }
        sort(p, p + m);
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                if (v[i] > v1) {
                    cnt++;
                    for (int j = 0; j < m; j++) {
                        if (p[j] >= d[i]) {
                            p1[j].push_back(cnt);
                            p2[cnt]++;
                        }
                    }
                }
            } else if (a[i] > 0) {
                bool cnt3 = 0;
                for (int j = 0; j < m; j++) {
                    if (p[j] >= d[i] && v[i] * v[i] + 2 * a[i] * (p[j] - d[i]) > v1 * v1) {
                        if (!cnt3) {
                            cnt3 = 1;
                            cnt++;
                        }
                        p1[j].push_back(cnt);
                        p2[cnt]++;
                    }
                }
            } else {
                if (v[i] > v1) {
                    bool cnt2 = 0;
                    for (int j = 0; j < m; j++) {
                        if (p[j] >= d[i] && v[i] * v[i] - 2 * a[i] * (p[j] - d[i]) > v1 * v1) {
                            if (!cnt2) {
                                cnt2 = 1;
                                cnt++;
                            }
                            p1[j].push_back(cnt);
                            p2[cnt]++;
                        } else if (p[j] >= d[i]) {
                            break;
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
        int ans = 0;
        for (int i = 0; i < m; i++) {
            bool cnt4 = 0;
            for (int j = 0; j < p1[i].size(); j++) {
                if (p2[p1[i][j]] <= 1) {
                    cnt4 = 1;
                    break;
                }
            }
            if (!cnt4) {
                ans++;
                for (int j = 0; j < p1[i].size(); j++) {
                    p2[p1[i][j]]--;
                }
            }
        }
        cout << ans << endl;
	}

	return 0;
}
